<template>
    <div>
      <Card class="clearfix" style="padding-bottom: 16px">
        <p slot="title">
          权限列表
        </p>

        <Form label-position="left" :label-width="72">
          <Row :gutter="15">
            <i-col span="6">
              <FormItem label="角色名称：">
                <Input v-model="searchvalue" clearable placeholder="请输入角色名称"/>
              </FormItem>
            </i-col>
            <i-col span="6">
              <Button type="success" @click="searchData" icon="ios-search" >搜索</Button>
            </i-col>
          </Row>
        </Form>
        <div class="btn-group-list">
          <Button  @click="addData" v-if="access.add" icon="ios-checkmark" style="width:90px;" type="primary">新增</Button>
        </div>
        <br>
         <div>
            <can-edit-table refs="table1" v-model="tableData" :access="access" :table-data="tableData"></can-edit-table>
         </div>
         <Page ref="pages" :total="itemTotal" show-total style="float: right; margin-top: 20px" @on-change="getList"></Page>
      </Card>
    </div>
</template>

<script>
import canEditTable from './components/canEditTable.vue'
import ajax from '../../../libs/axios.js'
import {otherRouter} from '@/router/router'
export default {
    name: 'setroleindex',
    components: {
        canEditTable
    },
    data () {
        return {
            access: {
                add:false,
                edit: false,
                func: false,
                remove: false
            },
            searchvalue: '',    // 角色名称
            itemTotal: 0,       // table条数
            tableData: [],      // table数据集
        }
    },
    mounted () {
        this.init()
        this.getCount();
    },
    activated () {
        this.init()
    },
    methods: {
        // 初始化
        init () {
            this.$store.commit('setActiveName', 'setroleindex');
            let vm = this
            vm.access.edit = otherRouter.children.findIndex(item => item.name === 'editrole') >= 0
            vm.access.func = otherRouter.children.findIndex(item => item.name === 'rolefunction') >= 0
            vm.access.add = otherRouter.children.findIndex(item => item.name === 'addrole') >= 0
            vm.access.remove = true;
            console.log(vm.access.edit, '======', otherRouter.children)
            this.getList('1')
        },
        // 搜索按钮
        searchData () {
            this.getList('1')
            this.getCount();
        },
        // 新增按钮
        addData () {
            let argu = {
                id: 'add'
            }
            this.$router.push({
                name: 'addrole',
                params: argu
            })
        },
        getCount() {
            let url = 'adminlogin/role/selectCount'
            let data = {
                rolename: this.searchvalue
            }
            ajax
                .formRes(url, data)
                .then(res => {
                    if(res.code == 200){
                        this.itemTotal = res.count;
                    }
                })
                .catch(res => {
                    console.log('有错误信息')
                    // fail
                })
        },
        getList (page) {
            let url = 'adminlogin/role/selectCjRole'
            let data = {
                rolename: this.searchvalue,
                pageSize: 10,
                pageNum: page
            }
            ajax
                .formRes(url, data)
                .then(res => {
                    if(res.code == 200){
                        this.tableData = res.data
                    }
                    
                })
                .catch(res => {
                    console.log('有错误信息')
                })
        }
    },
}
</script>


<style lang="less">
    @import "../../../styles/common.less";
</style>

